import Fly from 'flyio'
const request = new Fly()
import { toast } from '@/utils/index'

request.interceptors.request.use((req) => {
    const token = wx.getStorageSync('token')
    req.headers['content-type'] = 'application/json'
    if (token) {
        req.headers['token'] = token
    }
    return req
})

request.interceptors.response.use(
    (response, promise) => {
        let that = this
        if (response.data.code === 401) {
            console.log(response.data.code)
            wx.redirectTo({ url: '/pages/authorization/main' })
            return
        } else if (response.data.code != 0) {
            toast(response.data.msg)
            return
        }
        return promise.resolve(response)
    }
)
export default request